<?php

use Biz\model\trade\Order as mOrder;
use Biz\service\trade\Order as OrderService;
use Doraemon\tools\ActionLog;
use Biz\module\Classes\OrderInfo as clsOrderInfo;
use Biz\module\Classes\Order as clsOrder;

class ListAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;
    const PAGE_SIZE = 30;

    public function main()
    {
        $status = $this->getRequest()->getQuery('status', 0);
        $status = $status ? $status : null;
        $page = $this->getRequest()->getQuery('page', 1);
        $from = $this->getRequest()->getQuery('from', '');//todo 告知客户端
        $page = $page ? $page : 1;
        $isCommented = null;
        $tab = mOrder::$statusDesc[$status];


        switch ($status) {
            case 0://全部
                $status = null;
                $tab = '全部';
                break;
            case 10:
                $tab = '待付款';
                break;
            case 20:
                $tab = '待发货';
                break;
            case 21:
                $tab = '待收货';
                break;
            case 31://待评价
                $status = mOrder::STATUS_SUCCESS;
                $isCommented = 0;
                $tab = '待评分';
                break;
            case 32://已评价
                $status = mOrder::STATUS_SUCCESS;
                $isCommented = 1;
                $tab = '已评分';
                break;
        }

        $data = OrderService::getList($this->uid, $status, $page, self::PAGE_SIZE, $isCommented);

        $data = $data ? $data : (object)$data;
        ActionLog::log($this->uid, ['from' => $from, 'tab' => $tab], ActionLog::BIZ_ORDER_LIST);
        $this->setSuccess($data);
    }

}
